Class Particles

java.lang.Object
com.fs.starfarer.api.combat.BaseCombatLayeredRenderingPlugin
particleengine.Particles
All Implemented Interfaces:
com.fs.starfarer.api.campaign.listeners.CurrentLocationChangedListener, com.fs.starfarer.api.combat.CombatLayeredRenderingPlugin, com.fs.starfarer.api.EveryFrameScript

public class Particles extends com.fs.starfarer.api.combat.BaseCombatLayeredRenderingPlugin implements com.fs.starfarer.api.EveryFrameScript, com.fs.starfarer.api.campaign.listeners.CurrentLocationChangedListener
Particle system implementation. Create a default emitter via initialize(org.lwjgl.util.vector.Vector2f, int, int, int) or a custom emitter by extending IEmitter, set the emitter's properties with methods in Emitter, and generate particles using an emitter with burst(particleengine.IEmitter, int) or stream(particleengine.IEmitter, int, float, float).
  • Constructor Details

    • Particles

      public Particles()
  • Method Details

    • reportCurrentLocationChanged

      public void reportCurrentLocationChanged(com.fs.starfarer.api.campaign.LocationAPI prev, com.fs.starfarer.api.campaign.LocationAPI curr)
      Specified by:
      reportCurrentLocationChanged in interface com.fs.starfarer.api.campaign.listeners.CurrentLocationChangedListener
    • getActiveLayers

      public EnumSet<com.fs.starfarer.api.combat.CombatEngineLayers> getActiveLayers()
      Specified by:
      getActiveLayers in interface com.fs.starfarer.api.combat.CombatLayeredRenderingPlugin
      Overrides:
      getActiveLayers in class com.fs.starfarer.api.combat.BaseCombatLayeredRenderingPlugin
    • getRenderRadius

      public float getRenderRadius()
      Specified by:
      getRenderRadius in interface com.fs.starfarer.api.combat.CombatLayeredRenderingPlugin
      Overrides:
      getRenderRadius in class com.fs.starfarer.api.combat.BaseCombatLayeredRenderingPlugin
    • isDone

      public boolean isDone()
      Specified by:
      isDone in interface com.fs.starfarer.api.EveryFrameScript
    • runWhilePaused

      public boolean runWhilePaused()
      Specified by:
      runWhilePaused in interface com.fs.starfarer.api.EveryFrameScript
    • advance

      public void advance(float amount)
      Specified by:
      advance in interface com.fs.starfarer.api.combat.CombatLayeredRenderingPlugin
      Specified by:
      advance in interface com.fs.starfarer.api.EveryFrameScript
      Overrides:
      advance in class com.fs.starfarer.api.combat.BaseCombatLayeredRenderingPlugin
    • render

      public void render(com.fs.starfarer.api.combat.CombatEngineLayers layer, com.fs.starfarer.api.combat.ViewportAPI viewport)
      Specified by:
      render in interface com.fs.starfarer.api.combat.CombatLayeredRenderingPlugin
      Overrides:
      render in class com.fs.starfarer.api.combat.BaseCombatLayeredRenderingPlugin
    • anchorEmitter

      public static void anchorEmitter(IEmitter emitter, com.fs.starfarer.api.combat.CombatEntityAPI entity)
      Combat only. Anchors an emitter to a CombatEntityAPI. Sets the emitter's location to the entity's location every frame until the entity is no longer in play. Will also kill any particle streams using an anchored emitter if that emitter's anchor entity is no longer in play.
      By default, particles will only take into account their emitter's location at the time of generation. To change this behavior so that particles follow their emitter throughout their lifecycle, use IEmitter.enableDynamicAnchoring().
      Parameters:
      emitter - Emitter to anchor
      entity - The combat entity to anchor to
    • initialize

      public static Emitter initialize(org.lwjgl.util.vector.Vector2f location, int sfactor, int dfactor, int blendMode)
      Same as initialize(Vector2f, SpriteAPI, int, int, int), but uses a default particle sprite instead of sampling a texture.
    • initialize

      public static Emitter initialize(org.lwjgl.util.vector.Vector2f location)
      Same as initialize(Vector2f, SpriteAPI, int, int, int), but uses the default additive blending and a default particle sprite.
    • initialize

      public static Emitter initialize(org.lwjgl.util.vector.Vector2f location, com.fs.starfarer.api.graphics.SpriteAPI sprite, int sfactor, int dfactor, int blendMode)
      Initialize an Emitter. The Emitter's location will be set to location, specified in world coordinates. The Emitter's attributes will be initialized to default values and should be set in subsequent calls. To generate particles, use burst(particleengine.IEmitter, int) or stream(particleengine.IEmitter, int, float, float).

      Note: Does not load sprite's texture into memory. Textures not in data/config/settings.json are not automatically loaded. Use initialize(Vector2f, String, int, int, int) to load loose textures into memory.
      Parameters:
      sprite - The texture that the particles should sample when rendered. Must already have been loaded into memory.
      sfactor - Source blend factor.
      dfactor - Destination blend factor.
      blendMode - Blending operation.
      Returns:
      A default Emitter
    • createCopy

      public static Emitter createCopy(Emitter copy, com.fs.starfarer.api.graphics.SpriteAPI sprite, int sfactor, int dfactor, int blendMode)
      Initializes an Emitter with the given sprite and blend mode settings, and then copies all of copy's properties to it. Changes in properties of the resulting emitter are not reflected in the original copy, nor vice versa.
      Parameters:
      copy - Emitter whose properties to copy.
      sprite - Texture to use for the new emitter.
      sfactor - Source blend factor.
      dfactor - Destination blend factor.
      blendMode - Blending operation.
      Returns:
      An Emitter with the same properties as copy.
    • createCopy

      public static Emitter createCopy(Emitter copy, com.fs.starfarer.api.graphics.SpriteAPI sprite)
      Same as createCopy(Emitter, SpriteAPI, int, int, int), but also copies copy's blending settings.
      Parameters:
      copy - Emitter whose properties to copy
      sprite - Texture to use for the new emitter
      Returns:
      An emitter with the same properties as copy
    • createCopy

      public static Emitter createCopy(Emitter copy)
      Same as createCopy(Emitter, SpriteAPI, int, int, int), but also copies copy's sprite and blending settings.
      Parameters:
      copy - Emitter whose properties to copy
      Returns:
      An emitter with the same properties as copy
    • initialize

      public static Emitter initialize(org.lwjgl.util.vector.Vector2f location, com.fs.starfarer.api.graphics.SpriteAPI sprite)
      Same as initialize(Vector2f, SpriteAPI, int, int, int), but uses additive blending by default.
    • initialize

      public static Emitter initialize(org.lwjgl.util.vector.Vector2f location, String spriteLoc, int sfactor, int dfactor, int blendMode)
      Takes the sprite location instead of a SpriteAPI object. Will also load the texture into memory if it hasn't already been loaded. All textures loaded this way are automatically unloaded periodically.
      See Also:
    • initialize

      public static Emitter initialize(org.lwjgl.util.vector.Vector2f location, String spriteLoc)
      Uses default additive blending.
      See Also:
    • burst

      public static boolean burst(IEmitter emitter, int count)
      Generates an instantaneous burst of particles.
      Parameters:
      emitter - IEmitter to use.
      count - Number of particles to generate.
      Returns:
      Whether the particles were successfully generated.
    • stream

      public static void stream(IEmitter emitter, int particlesPerBurst, float particlesPerSecond, float duration)
      Generates a continuous stream of particles.
      Parameters:
      emitter - IEmitter to use.
      particlesPerBurst - Number of particles that should be generated at once.
      particlesPerSecond - Total number of particles generated per second.
      duration - Amount of time this particle stream should last. If negative, the stream will never expire.
    • stream

      public static <T extends IEmitter> void stream(T emitter, int particlesPerBurst, float particlesPerSecond, float maxDuration, @Nullable @Nullable Particles.StreamAction<T> doBeforeGenerating)
      Generates a continuous stream of particles.
      Parameters:
      emitter - IEmitter to use.
      particlesPerBurst - Number of particles that should be generated at once.
      particlesPerSecond - Total number of particles generated per second.
      maxDuration - Maximum amount of time this particle stream should last. If negative, the stream will not naturally expire.
      doBeforeGenerating - Custom function that's called immediately before each particle generation sequence in this stream. Returning false will end the stream.
    • stream

      public static <T extends IEmitter> void stream(T emitter, int particlesPerBurst, float particlesPerSecond, float maxDuration, @Nullable @Nullable Particles.StreamAction<T> doBeforeGenerating, @Nullable @Nullable Particles.StreamAction<T> doWhenFinished)
      Generates a continuous stream of particles.
      Parameters:
      emitter - IEmitter to use.
      particlesPerBurst - Number of particles that should be generated at once.
      particlesPerSecond - Total number of particles generated per second.
      maxDuration - Maximum amount of time this particle stream should last. If negative, the stream will not naturally expire.
      doBeforeGenerating - Custom function that's called immediately before each particle generation sequence in this stream. Returning false will end the stream.
      doWhenFinished - Custom function that's called when the stream expires, which can occur either naturally, if doBeforeGenerating returns false, or if the stream's emitter's anchor point is removed from play. The return value is not used.